﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.t202Menu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void t202_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            t202Mgr mgr = new t202Mgr();
            e.Total = int.Parse(mgr.GetRecordCount_t202(e.Parameters[t202_Filter.ParamPrefix]));
            IList<t202> list = mgr.FindAllByPage_t202(e.Start.ToString(), e.Limit.ToString(), e.Parameters[t202_Filter.ParamPrefix]);
            t202_MainStore.DataSource = list;
            t202_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            t202Mgr mgr = new t202Mgr();
            RowSelectionModel sm = t202_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                t202 _t202 = new t202();
                _t202.t202_00 = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_t202(_t202))
                {
                    log.Debug("t202中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            t202_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            t202Mgr mgr = new t202Mgr();
            t202 _t202 = new t202();
            if (Hid.Text.Length > 0)
                _t202 = mgr.FindById_t202(int.Parse(Hid.Text));
            
			_t202.t202_01 = Txtt202_01.Text.Trim();
			_t202.t202_02 = Txtt202_02.Text.Trim();
			_t202.t202_03 = Txtt202_03.Text.Trim();
			_t202.t202_72 = Txtt202_72.Text.Trim();
			_t202.t202_73 = Txtt202_73.Text.Trim();
			_t202.t202_74 = Txtt202_74.Text.Trim();
			_t202.t202_04 = Txtt202_04.Text.Trim();
			_t202.t202_76 = Txtt202_76.Text.Trim();
			_t202.t202_77 = Txtt202_77.Text.Trim();
			_t202.t202_05 = Txtt202_05.Text.Trim();
			_t202.t202_79 = Txtt202_79.Text.Trim();
			_t202.t202_80 = Txtt202_80.Text.Trim();
			_t202.t202_81 = Txtt202_81.Text.Trim();
			_t202.t202_06 = Txtt202_06.Text.Trim();
			_t202.t202_83 = Txtt202_83.Text.Trim();
			_t202.t202_84 = Txtt202_84.Text.Trim();
			_t202.t202_85 = Txtt202_85.Text.Trim();
			_t202.t202_07 = Txtt202_07.Text.Trim();
			_t202.t202_87 = Txtt202_87.Text.Trim();
			_t202.t202_88 = Txtt202_88.Text.Trim();
			_t202.t202_89 = Txtt202_89.Text.Trim();
			_t202.t202_08 = Txtt202_08.Text.Trim();
			_t202.t202_91 = Txtt202_91.Text.Trim();
			_t202.t202_92 = Txtt202_92.Text.Trim();
			_t202.t202_93 = Txtt202_93.Text.Trim();
			_t202.t202_09 = Txtt202_09.Text.Trim();
			_t202.t202_95 = Txtt202_95.Text.Trim();
			_t202.t202_96 = Txtt202_96.Text.Trim();
			_t202.t202_97 = Txtt202_97.Text.Trim();
			_t202.t202_10 = Txtt202_10.Text.Trim();
			_t202.t202_99 = Txtt202_99.Text.Trim();
			_t202.t202_100 = Txtt202_100.Text.Trim();
			_t202.t202_101 = Txtt202_101.Text.Trim();
			_t202.t202_11 = Txtt202_11.Text.Trim();
			_t202.t202_103 = Txtt202_103.Text.Trim();
			_t202.t202_104 = Txtt202_104.Text.Trim();
			_t202.t202_105 = Txtt202_105.Text.Trim();
			_t202.t202_12 = Txtt202_12.Text.Trim();
			_t202.t202_107 = Txtt202_107.Text.Trim();
			_t202.t202_108 = Txtt202_108.Text.Trim();
			_t202.t202_109 = Txtt202_109.Text.Trim();
			_t202.t202_13 = Txtt202_13.Text.Trim();
			_t202.t202_110 = Txtt202_110.Text.Trim();
			_t202.t202_111 = Txtt202_111.Text.Trim();
			_t202.t202_112 = Txtt202_112.Text.Trim();
			_t202.t202_14 = Txtt202_14.Text.Trim();
			_t202.t202_15 = Txtt202_15.Text.Trim();
			_t202.t202_16 = Txtt202_16.Text.Trim();
			_t202.t202_113 = Txtt202_113.Text.Trim();
			_t202.t202_17 = Txtt202_17.Text.Trim();
			_t202.t202_18 = Txtt202_18.Text.Trim();
			_t202.t202_114 = Txtt202_114.Text.Trim();
			_t202.t202_19 = Txtt202_19.Text.Trim();
			_t202.t202_20 = Txtt202_20.Text.Trim();
			_t202.t202_70 = Txtt202_70.Text.Trim();
			_t202.t202_21 = Txtt202_21.Text.Trim();
			_t202.t202_22 = Txtt202_22.Text.Trim();
			_t202.t202_23 = Txtt202_23.Text.Trim();
			_t202.collection_time = Txtcollection_time.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_t202(_t202);
            else
                isok = mgr.Add_t202(_t202);
            if (isok)
            {
                t202_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("t202中执行了保存（插入或修改），并成功");
                t202_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}